<?php
 
include_once("./configure/configure.php");						//--> global var
include_once("./admin/tools/smarty/libs/Smarty.class.php");		//--> out template
include_once("utils/FileUtils.php");				//--> file utils

include_once("impl/CategoryImpl.php");
include_once("impl/ContentImpl.php");
include_once("impl/TagImpl.php");

include_once("includeSmarty.php");


$keyword= $_GET['keyword'];
$page 	= $_GET['page'];


if(empty($keyword)){
	$location = HOME_URL_HTTP;
	
	header("Location: $location");
	exit;
}


$cacheId = $keyword . '_' . $page;

/*----- out html -----*/
$SUB_DIR	= FileUtils::getDirByString($keyword) . '/';

$smarty->compile_dir  	= COMPILE_DIR . '/search/' . $SUB_DIR;
$smarty->cache_dir  	= CACHE_DIR . '/search/' . $SUB_DIR;

if(!$smarty->isCached('searches.html', $cacheId, $cacheId)){	
	$oCatImpl 		= new CategoryImpl(DB_TAG_MM);
	$tagImpl		= new TagImpl(DB_TAG_MM);
	$oContImpl 		= new ContentImpl(DB_TAG_MM);
	
	$oContents	= $oContImpl->getSearchContentPage($keyword, $page, 18);

	
	$oCats 			= $oCatImpl->getLeaf();
	$oTags			= $tagImpl->getTags();
	
	$smarty->assign('oContents', $oContents);
		
	$smarty->assign('oCats', $oCats);
	$smarty->assign('oTags', $oTags);
	
	
	$smarty->assign('id', $id);
	$smarty->assign('order', $order);
	
	$smarty->assign('pageList', $oContImpl->getPageList(9));
	$smarty->assign('nextPage', $oContImpl->getNextPage());
	$smarty->assign('prePage', $oContImpl->getPrePage());
	$smarty->assign('pageCount', $oContImpl->getPageCount());
	$smarty->assign('page', $oContImpl->getPage());
}


$smarty->assign('HOME_URL', HOME_URL);
$smarty->assign('HOME_URL_HTTP', HOME_URL_HTTP);
$smarty->assign('DEBUG', DEBUG);

$smarty->assign('keyword', $keyword);

$smarty->display('searches.html', $cacheId, $cacheId);
?>
